﻿
module("Collision")
test("Collision with Left and Top", function () {
    var earth = new tetris.Earth(4, 8);

    sq = new tetris.FallingSquare();
    sq.moveTo(1, 3);
    earth.add(sq);

    sq = new tetris.FallingSquare();
    sq.moveTo(3, 7);

    sq.moveTo(0, 0);
    sq.rotate();
    sq.rotate();

    var collider = new tetris.CollisionDetector();
    var collisions = collider.getCollisions(sq, earth);

    equal(undefined, collisions[tetris.CollisionType.Earth], "There is no collision with the earth");
    equal("LeftEdge", collisions[tetris.CollisionType.LeftEdge], "There is collision with the Left Edge");
    equal(undefined, collisions[tetris.CollisionType.RightEdge], "There is no collision with the Right Edge");
    equal("TopEdge", collisions[tetris.CollisionType.TopEdge], "There is collision with the Top Edge");
});

test("Collision with Earth", function () {
    var earth = new tetris.Earth(10, 20);

    sq = new tetris.FallingSquare();
    sq.moveTo(1, 3);
    earth.add(sq);

    sq = new tetris.FallingSquare();
    sq.moveTo(4, 7);

   
    sq.rotate();
    sq.rotate();
    earth.add(sq);

    var collider = new tetris.CollisionDetector();
    var collisions = collider.getCollisions(sq, earth);

    equal("Earth", collisions[tetris.CollisionType.Earth], "There is collision with the earth");
    equal(undefined, collisions[tetris.CollisionType.LeftEdge], "There is no collision with the Left Edge");
    equal(undefined, collisions[tetris.CollisionType.RightEdge], "There is no collision with the Right Edge");
    equal(undefined, collisions[tetris.CollisionType.TopEdge], "There is no collision with the Top Edge");
});

test("Collision Earth and Right", function () {
    var earth = new tetris.Earth(4, 8);

    var sq = new tetris.FallingSquare();
    sq.moveTo(0, 6);
    earth.add(sq);

    sq = new tetris.FallingSquare();
    sq.moveTo(2, 5);
    earth.add(sq);

    sq = new tetris.FallingSquare();
    sq.moveTo(1, 3);
    earth.add(sq);

    sq = new tetris.FallingSquare();
    sq.moveTo(3, 7);

    //sq.moveTo(0, 0);
    //sq.rotate();
    //sq.rotate();

    var collider = new tetris.CollisionDetector();
    var collisions = collider.getCollisions(sq, earth);

    equal("Earth", collisions[tetris.CollisionType.Earth], "There is collision with the earth");
    equal(undefined, collisions[tetris.CollisionType.LeftEdge], "There is no collision with the Left Edge");
    equal("RightEdge", collisions[tetris.CollisionType.RightEdge], "There is  collision with the Right Edge");
    equal(undefined, collisions[tetris.CollisionType.TopEdge], "There is no collision with the Top Edge");
});

test("Collision at Top", function () {
    var earth = new tetris.Earth(4, 8);

    var sq = new tetris.FallingSquare();
    sq.moveTo(0, 6);
    earth.add(sq);

    sq = new tetris.FallingSquare();
    sq.moveTo(2, 5);
    earth.add(sq);

    sq = new tetris.FallingSquare();
    sq.moveTo(1, 3);
    earth.add(sq);

    sq = new tetris.FallingSquare();
    sq.moveTo(3, 7);

    sq.moveTo(0, 0);
    sq.rotate();
    //sq.rotate();

    var collider = new tetris.CollisionDetector();
    var collisions = collider.getCollisions(sq, earth);

    equal(undefined, collisions[tetris.CollisionType.Earth], "There is no collision with the earth");
    equal(undefined, collisions[tetris.CollisionType.LeftEdge], "There is no collision with the Left Edge");
    equal(undefined, collisions[tetris.CollisionType.RightEdge], "There is no collision with the Right Edge");
    equal("TopEdge", collisions[tetris.CollisionType.TopEdge], "There is  collision with the Top Edge");
});
